
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Java 基础 -- 使用 JOOR 实现反射 · 寒江蓑笠的博客</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="介绍JOOR的用法">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="java-basic-annotation.html" />
    
    
    <link rel="prev" href="../../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.1" data-path="java-basic-joor.html">
            
                <a href="java-basic-joor.html">
            
                    
                    Java 基础 -- 使用 JOOR 实现反射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="java-basic-annotation.html">
            
                <a href="java-basic-annotation.html">
            
                    
                    Java基础 -- 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3" data-path="java-basic-threadlocal.html">
            
                <a href="java-basic-threadlocal.html">
            
                    
                    Java 基础 -- ThreadLocal
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4" data-path="java-development-skills-get-stacktrace.html">
            
                <a href="java-development-skills-get-stacktrace.html">
            
                    
                    Java 开发技巧 -- 获取 Java 的调用栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5" data-path="java-basic-concurrent-map-collection.html">
            
                <a href="java-basic-concurrent-map-collection.html">
            
                    
                    Java 基础 -- 并发集合的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6" data-path="java-dynamic-proxy-invocationhandler-demo.html">
            
                <a href="java-dynamic-proxy-invocationhandler-demo.html">
            
                    
                    Java InvocationHandler 实现动态代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7" data-path="java-basic-try-catch-finally.html">
            
                <a href="java-basic-try-catch-finally.html">
            
                    
                    Java 基础 -- 深入理解 try catch finally
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8" data-path="java-basic-reflect.html">
            
                <a href="java-basic-reflect.html">
            
                    
                    Java 基础 -- 反射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.9" data-path="java-basic-io-stream.html">
            
                <a href="java-basic-io-stream.html">
            
                    
                    Java IO -- IO流的概念和分类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10" data-path="java-basic-final.html">
            
                <a href="java-basic-final.html">
            
                    
                    Java 基础 -- 深入理解 final 修饰符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.11" data-path="java-basic-memory-manage-constructor.html">
            
                <a href="java-basic-memory-manage-constructor.html">
            
                    
                    Java 内存管理 -- 父子实例的内存控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.12" data-path="java-basic-memory-manage-inherit-object.html">
            
                <a href="java-basic-memory-manage-inherit-object.html">
            
                    
                    Java 内存管理 -- 构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.13" data-path="java-basic-memory-manage-memory-area.html">
            
                <a href="java-basic-memory-manage-memory-area.html">
            
                    
                    Java 内存管理 -- 内存区域的划分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.14" data-path="java-basic-memory-manage-variable.html">
            
                <a href="java-basic-memory-manage-variable.html">
            
                    
                    Java 内存管理 -- 变量的内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.15" data-path="java-basic-knowledge-generic.html">
            
                <a href="java-basic-knowledge-generic.html">
            
                    
                    Java 基础 -- 范型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.16" data-path="java-basic-knowledge-auto-boxing.html">
            
                <a href="java-basic-knowledge-auto-boxing.html">
            
                    
                    Java 基础 -- 关于自动装箱和拆箱机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.17" data-path="java-basic-knowledge-parameter-passing.html">
            
                <a href="java-basic-knowledge-parameter-passing.html">
            
                    
                    Java 基础 -- 值传递、引用传递和参数传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.18" data-path="java-basic-stringbuilder-stringbuffer.html">
            
                <a href="java-basic-stringbuilder-stringbuffer.html">
            
                    
                    Java 基础 -- StringBuilder 和 StringBuffer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.19" data-path="java-basic-knowledge-about-string.html">
            
                <a href="java-basic-knowledge-about-string.html">
            
                    
                    Java 基础 -- 深入理解 String
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.20" data-path="java-basic-linkedhashmap.html">
            
                <a href="java-basic-linkedhashmap.html">
            
                    
                    Java 基础 -- LinkedHashMap 的使用和原理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Java 基础 -- 使用 JOOR 实现反射</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x6982;&#x8FF0;">&#x6982;&#x8FF0;</h2>
<p>&#x5728;&#x524D;&#x9762;&#x7684;&#x535A;&#x5BA2; <a href="http://www.heqiangfly.com/2014/11/02/java-basic-reflect/" target="_blank">Java &#x57FA;&#x7840; -- &#x53CD;&#x5C04; </a> &#x5217;&#x4E3E;&#x4E86;Java&#x53CD;&#x5C04;&#x7684;&#x4E00;&#x4E9B;&#x4F7F;&#x7528;&#xFF0C;&#x4E0B;&#x9762;&#x4ECB;&#x7ECD;&#x5F00;&#x6E90;&#x53CD;&#x5C04;&#x5DE5;&#x5177;JOOR&#x7684;&#x4F7F;&#x7528;&#x3002;
JOOR &#x5C01;&#x88C5;&#x4E86;&#x53CD;&#x5C04;&#x64CD;&#x4F5C;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x6D41;&#x5F0F;&#x8C03;&#x7528;&#xFF0C;&#x53EA;&#x9700;&#x51E0;&#x884C;&#x4EE3;&#x7801;&#x5C31;&#x5B9E;&#x73B0;&#x4E86;&#x524D;&#x9762;&#x535A;&#x5BA2;&#x4E2D;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x53CD;&#x5C04;&#x3002;
<a href="https://github.com/jOOQ/jOOR" target="_blank">GitHub &#x5730;&#x5740;</a></p>
<h2 id="&#x4F7F;&#x7528;&#x65B9;&#x6CD5;">&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</h2>
<p>gradle&#x4E2D;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre><code>compile &apos;org.jooq:joor:0.9.5&apos;
</code></pre><pre><code>    public void testJoor(){
        Reflect.on(&quot;com.example.heqiang.testsomething.OuterClass&quot;)
                .create()
                .field(&quot;mInnerClass&quot;)
                .call(&quot;printInt&quot;);

        OuterClass outerClass = new OuterClass();
        Reflect.on(outerClass).field(&quot;mInnerClass&quot;).call(&quot;printInt&quot;);
        Reflect.on(outerClass).field(&quot;mInnerClass&quot;).set(&quot;mInt&quot;, 8);
        Reflect.on(outerClass).field(&quot;mInnerClass&quot;).call(&quot;printInt&quot;);

        Reflect.on(object).call(&quot;testMethod&quot;,1);
    }
</code></pre><pre><code>String world = on(&quot;java.lang.String&quot;)  // Like Class.forName()
                .create(&quot;Hello World&quot;) // Call most specific matching constructor
                .call(&quot;substring&quot;, 6)  // Call most specific matching substring() method
                .call(&quot;toString&quot;)      // Call toString()
                .get();                // Get the wrapped object, in this case a String
</code></pre><h2 id="&#x4EE3;&#x7801;&#x89E3;&#x91CA;">&#x4EE3;&#x7801;&#x89E3;&#x91CA;</h2>
<p>Reflect &#x63D0;&#x4F9B;&#x4E86;&#x4E09;&#x4E2A;&#x53D8;&#x91CF;&#xFF1A;classCache&#x3001;classCache&#x548C;classCache&#x5206;&#x522B;&#x6765;&#x505A;&#x7F13;&#x5B58;&#x4F7F;&#x7528;&#x3002;
&#x9759;&#x6001;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li>on(String name)&#xFF1A;&#x6839;&#x636E;&#x7C7B;&#x540D;&#x521B;&#x5EFA; Reflect &#x5BF9;&#x8C61;&#x3002;</li>
<li>on(String name, ClassLoader classLoader)&#xFF1A;&#x6839;&#x636E;&#x7C7B;&#x540D;&#x548C;ClassLoader&#x521B;&#x5EFA; Reflect &#x5BF9;&#x8C61;&#x3002;</li>
<li>on(Class&lt;?&gt; clazz)&#xFF1A;&#x6839;&#x636E;Class&#x521B;&#x5EFA; Reflect &#x5BF9;&#x8C61;&#x3002;</li>
<li>on(Object object)&#xFF1A;&#x6839;&#x636E;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x521B;&#x5EFA; Reflect &#x5BF9;&#x8C61;&#x3002;</li>
<li>accessible(@NonNull T accessible)</li>
</ul>
<p>on &#x65B9;&#x6CD5;&#x90FD;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A; Reflect &#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li>get()&#xFF1A;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x5305;&#x88C5;&#x5BF9;&#x8C61;&#xFF0C;&#x6BD4;&#x5982;&#x4E0A;&#x9762;&#x7684;&#x6267;&#x884C;&#x65B9;&#x6CD5;&#x540E;&#x83B7;&#x53D6;&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;</li>
<li>set(String name, Object value)&#xFF1A;&#x4E3A;&#x67D0;&#x4E2A;Field&#x8BBE;&#x7F6E;&#x503C;</li>
<li>get(String name)&#xFF1A;&#x83B7;&#x53D6;&#x67D0;&#x4E2A;Field&#x7684;&#x503C;</li>
<li>field(String name)&#xFF1A;&#x83B7;&#x53D6;&#x67D0;&#x4E2A;Field</li>
<li>fields()&#xFF1A;&#x83B7;&#x53D6;&#x6240;&#x6709;Field</li>
<li>call(String name)&#xFF1A;&#x6267;&#x884C;&#x67D0;&#x4E2A;Method</li>
<li>call(String name, Object... args)&#xFF1A;&#x6267;&#x884C;&#x67D0;&#x4E2A;Method&#xFF0C;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;&#x53C2;&#x6570;</li>
<li>create()&#xFF1A;&#x8C03;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;</li>
<li>create(Object... args)&#xFF1A;&#x8C03;&#x7528;&#x5E26;&#x53C2;&#x6570;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;</li>
<li><code>as(Class&lt;P&gt; proxyType)</code></li>
</ul>
<h2 id="&#x5F02;&#x5E38;&#x5904;&#x7406;">&#x5F02;&#x5E38;&#x5904;&#x7406;</h2>
<p>JOOR &#x628A;&#x53CD;&#x5C04;&#x76F8;&#x5173;&#x7684;&#x5F02;&#x5E38;&#x90FD;&#x7EDF;&#x4E00;&#x8F6C;&#x6210;&#x4E86; ReflectException &#xFF0C;&#x8FD9;&#x4E2A;&#x5F02;&#x5E38;&#x7EE7;&#x627F;&#x81EA; RuntimeException&#xFF0C;&#x4E0D;&#x662F;&#x5F3A;&#x5236;&#x6355;&#x83B7;&#x7684;&#x5F02;&#x5E38;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x5199;&#x4EE3;&#x7801;&#x65F6;&#x4E00;&#x5B9A;&#x8981;&#x6CE8;&#x610F;&#x5BF9;&#x8FD9;&#x4E2A;&#x5F02;&#x5E38;&#x7684;&#x5904;&#x7406;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../../" class="navigation navigation-prev " aria-label="Previous page: Java">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="java-basic-annotation.html" class="navigation navigation-next " aria-label="Next page: Java基础 -- 注解">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Java 基础 -- 使用 JOOR 实现反射","categories":"Java","comments":true,"tags":["Java"],"description":"介绍JOOR的用法","date":"2017-01-20T10:00:00.000Z","level":"1.1.1","depth":2,"next":{"title":"Java基础 -- 注解","level":"1.1.2","depth":2,"path":"source/Java/java-basic-annotation.md","ref":"source/Java/java-basic-annotation.md","articles":[]},"previous":{"title":"Java","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[{"title":"Java 基础 -- 使用 JOOR 实现反射","level":"1.1.1","depth":2,"path":"source/Java/java-basic-joor.md","ref":"source/Java/java-basic-joor.md","articles":[]},{"title":"Java基础 -- 注解","level":"1.1.2","depth":2,"path":"source/Java/java-basic-annotation.md","ref":"source/Java/java-basic-annotation.md","articles":[]},{"title":"Java 基础 -- ThreadLocal","level":"1.1.3","depth":2,"path":"source/Java/java-basic-threadlocal.md","ref":"source/Java/java-basic-threadlocal.md","articles":[]},{"title":"Java 开发技巧 -- 获取 Java 的调用栈","level":"1.1.4","depth":2,"path":"source/Java/java-development-skills-get-stacktrace.md","ref":"source/Java/java-development-skills-get-stacktrace.md","articles":[]},{"title":"Java 基础 -- 并发集合的使用","level":"1.1.5","depth":2,"path":"source/Java/java-basic-concurrent-map-collection.md","ref":"source/Java/java-basic-concurrent-map-collection.md","articles":[]},{"title":"Java InvocationHandler 实现动态代理","level":"1.1.6","depth":2,"path":"source/Java/java-dynamic-proxy-invocationhandler-demo.md","ref":"source/Java/java-dynamic-proxy-invocationhandler-demo.md","articles":[]},{"title":"Java 基础 -- 深入理解 try catch finally","level":"1.1.7","depth":2,"path":"source/Java/java-basic-try-catch-finally.md","ref":"source/Java/java-basic-try-catch-finally.md","articles":[]},{"title":"Java 基础 -- 反射","level":"1.1.8","depth":2,"path":"source/Java/java-basic-reflect.md","ref":"source/Java/java-basic-reflect.md","articles":[]},{"title":"Java IO -- IO流的概念和分类","level":"1.1.9","depth":2,"path":"source/Java/java-basic-io-stream.md","ref":"source/Java/java-basic-io-stream.md","articles":[]},{"title":"Java 基础 -- 深入理解 final 修饰符","level":"1.1.10","depth":2,"path":"source/Java/java-basic-final.md","ref":"source/Java/java-basic-final.md","articles":[]},{"title":"Java 内存管理 -- 父子实例的内存控制","level":"1.1.11","depth":2,"path":"source/Java/java-basic-memory-manage-constructor.md","ref":"source/Java/java-basic-memory-manage-constructor.md","articles":[]},{"title":"Java 内存管理 -- 构造方法","level":"1.1.12","depth":2,"path":"source/Java/java-basic-memory-manage-inherit-object.md","ref":"source/Java/java-basic-memory-manage-inherit-object.md","articles":[]},{"title":"Java 内存管理 -- 内存区域的划分","level":"1.1.13","depth":2,"path":"source/Java/java-basic-memory-manage-memory-area.md","ref":"source/Java/java-basic-memory-manage-memory-area.md","articles":[]},{"title":"Java 内存管理 -- 变量的内存管理","level":"1.1.14","depth":2,"path":"source/Java/java-basic-memory-manage-variable.md","ref":"source/Java/java-basic-memory-manage-variable.md","articles":[]},{"title":"Java 基础 -- 范型","level":"1.1.15","depth":2,"path":"source/Java/java-basic-knowledge-generic.md","ref":"source/Java/java-basic-knowledge-generic.md","articles":[]},{"title":"Java 基础 -- 关于自动装箱和拆箱机制","level":"1.1.16","depth":2,"path":"source/Java/java-basic-knowledge-auto-boxing.md","ref":"source/Java/java-basic-knowledge-auto-boxing.md","articles":[]},{"title":"Java 基础 -- 值传递、引用传递和参数传递","level":"1.1.17","depth":2,"path":"source/Java/java-basic-knowledge-parameter-passing.md","ref":"source/Java/java-basic-knowledge-parameter-passing.md","articles":[]},{"title":"Java 基础 -- StringBuilder 和 StringBuffer","level":"1.1.18","depth":2,"path":"source/Java/java-basic-stringbuilder-stringbuffer.md","ref":"source/Java/java-basic-stringbuilder-stringbuffer.md","articles":[]},{"title":"Java 基础 -- 深入理解 String","level":"1.1.19","depth":2,"path":"source/Java/java-basic-knowledge-about-string.md","ref":"source/Java/java-basic-knowledge-about-string.md","articles":[]},{"title":"Java 基础 -- LinkedHashMap 的使用和原理","level":"1.1.20","depth":2,"path":"source/Java/java-basic-linkedhashmap.md","ref":"source/Java/java-basic-linkedhashmap.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"expandable-chapters":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"寒江蓑笠的博客","gitbook":"*"},"file":{"path":"source/Java/java-basic-joor.md","mtime":"2022-05-17T10:49:59.384Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-05-17T10:54:58.084Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

